﻿// JavaScript Document
/**
* @fileOverview  flw首页用
* @description 
* ......
* 20130610 mericmo 创建
* @author mericmo   
* @version 1.0.0
* @date 
* @bug 无
* @warning 无
**/
//===============全局变量定义区域=======================
/*命名空间说明：
* 命名空间: FLW.index
*/
$namespace("FLW.index");
FLW.index.globe = {
	docType:{
		"0":"全部",
		"1":"文库",
		"2":"视频",
		"3":"作者",
		"4":"专题",
		"5":"其他"
	},//资料类别
	iLogin:"http://localhost:8080/web/login",//登录接口：username=hsia@163.com&password=123456
	registerUrl:"./login/register.html"//temp注册页面地址
};
var other = FLW.index;
//初始化
FLW.index.init = function(d){
	//初始数据
	$extend(FLW.index.globe,d);
	//运行环境检查
	FLW.index.check();
	//页面渲染
	FLW.index.render();
};
//运行环境检查
FLW.index.check = function(){
};
//页面渲染
FLW.index.render =function(){
	//大图轮播 巨无霸
	FLW.index.initBanner();
	//导航下拉菜单初始化 //退后处理，首先加载图片
	FLW.index.initNav();
	//初始化搜索区域
	FLW.index.initSearch();
	//初始化登录组件
	FLW.index.initLogin();
};
//导航下拉菜单初始化
FLW.index.initNav =function(){
	var navBar=$id("nav_bar"),navBarTab=$child(navBar,"li");
	$array_walk(navBarTab,function(i,o){
		$hover({
			title:$child(o,"a")[0],
			content:$child(o,"div")[0]
		});
	});
};
//大图轮播 巨无霸
FLW.index.initBanner = function(){
	$slider({
		auto:true,
		effect:"fade",
		fadeLag:50,
		fadeTimes:1000,
		initSpeed:500,
		initIndex:1,
		width:740,				//内容区宽度
		height:320,				//内容区高度
		className:"cur",
		titleId:"slider_nav",    //tab标题的id
		titleTag:"li",    //tab的元素类型
		contentId:"slider_list",    //内容的id    
		contentTag:"li"    //内容元素类型
	});
};
//初始化搜索区域
FLW.index.initSearch =function(){
	var that = FLW.index.globe;
	//展示下拉
	$hover({
		title:$id("btn_select_search_type"),
		content:$id("search_type_list")
	});
	//选择类别
	var searchList = $id("search_type_list");
	$addEvent(searchList,"click",function(e){
		//冒泡事件
		var l = $getTarget(e,searchList,"li");
		var radioItem = $child(l,"input");
		if(radioItem&&radioItem[0]){
			radioItem[0].checked = true;
			var t=$getValue("search_type");
			$setHtml($id("btn_select_search_type"),that.docType[t]);
			
			$display("search_type_list","none");
		}
		
	});
};
//初始化登录组件
FLW.index.initLogin = function(){
	var that = FLW.index.globe;
	var showLoginBox = function(){
		var objTpl = $getStdTemplate("","login_module");
		//渲染数据
		//var html=$formatJson(objTpl.template,{"data":that});
		//弹出浮层
		var layLoginBox=$float({
			title:"登录福禄娃",
			html:objTpl.template,
			//titleId:"btn_close_login",
			//left:$getX(this)+100,
			//top:$getY(this),
			//width:'400',
			//height:"200",
			titleId:"login_title",
			fix:false,    //是否固定居中随屏幕滚动，如果为true则left和top无效
			style:"none",    //stand\none\poptip
			cover:false,    //显示覆盖背景
			closeId:"btn_close_login",
			onInit:function(){
				$addEvent($id("user_passport"),"focus",function(){
					if(this.value.trim()==this.defaultValue){this.value='';}
				});
				$addEvent($id("user_passport"),"blur",function(){
					if(this.value.trim()==''){this.value=this.defaultValue;}
				});
				$addEvent($id("user_password"),"focus",function(){
					if(this.value.trim()==this.defaultValue){this.value='';}
				});
				$addEvent($id("user_password"),"blur",function(){
					if(this.value.trim()==''){this.value=this.defaultValue;}
				});
				//登录按钮
				$addEvent($id("btn_login"),"click",function(){
					var uid = $id("user_passport").value.trim();
					uid == $id("user_passport").defaultValue ? uid="" :"";
					var skey = $id("user_password").value.trim();
					skey == $id("user_password").defaultValue ? skey="" :"";
					if(!uid || !skey){
						alert("请正确填写登录信息");
						return false;
					}
					window["_login_callback_"] = function(data){
						alert("登录请求已成功提交并回包。")
					};
					$cookie.setCookie("returl",window.location.href);
					$loadScript(other.globe.iLogin+$makeUrl({username:uid,password:skey,callback:"_login_callback_"}));
				});	
				$addEvent($id("btn_regisiter"),"click",function(){
					window.open(that.registerUrl,"_blank");
					layLoginBox.close();
				});
				return true;
			},
			onClose:function(){
				return true;
			},    //关闭事件
			dragble:true
		});
		
	};
	//导航登录按钮
	$addEvent($id("txt_login"),"click",showLoginBox);
};